package com.mjf.scala.chapter06

/**
 * 单例模式
 */
object Scala16_TestSingleton {

  def main(args: Array[String]): Unit = {

    val std1: Student16 = Student16.getInstance()
    val std2: Student16 = Student16.getInstance()
    println(std1, std2)   // (com.mjf.scala.chapter06.Student16@79698539,com.mjf.scala.chapter06.Student16@79698539)

  }

}

// 懒汉式
/*
object Student16 {

  private var s:Student16 = _

  synchronized(
  def getInstance(): Student16 = {
    if (s == null) {
      s = new Student16()
    }
    s
  })


}

// 主构造方法私有化
class Student16 private {

}
*/

// 饿汉式
object Student16 {

  private var s:Student16 = new Student16()

  def getInstance(): Student16 = {
    s
  }

}

// 主构造方法私有化
class Student16 private {

}
